package com.fuqi.android.zhongcai.business.shuig.view.activity;


import android.util.Log;
import android.view.View;
import android.widget.RatingBar;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.view.activity.BaseActivity;
import com.fuqi.android.zhongcai.business.shuig.request.api.OrderCommentApi;
import com.fuqi.android.zhongcai.business.shuig.request.result.OrderCommentResult;
import com.fuqi.android.zhongcai.business.shuig.view.widget.BGASortableNinePhotoLayoutView;
import com.fuqi.android.zhongcai.business.shuig.view.widget.CJRow.ARResponse;
import com.fuqi.framework.gson.GsonHelper;
import com.fuqi.framework.network.code.HandleCode;
import com.fuqi.framework.network.http.RequestManager;
import com.fuqi.framework.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import cn.bingoogolapple.photopicker.activity.BGAPhotoPreviewActivity;

public class CommentShowActivity extends BaseActivity implements BGASortableNinePhotoLayoutView.Delegate{
    @Bind(R.id.ratingbar_skill)
    RatingBar mRbskill;
    @Bind(R.id.ratingbar_service)
    RatingBar mRbservice;
    @Bind(R.id.ratingbar_speed)
    RatingBar mRbspeed;
    @Bind(R.id.et_remark)
    TextView etRemark;

    private BGASortableNinePhotoLayoutView ninePhotoLayout;
    private ArrayList<String> selectedPhotos = new ArrayList<>();
    ARResponse response;
    @Override
    public void initListener() {

    }

    @Override
    public void initData() {
        titleBar.setTitle("评论详情");
        response = new ARResponse(getIntent().getStringExtra("response"));
        RequestManager.getInstance().call(new OrderCommentApi(new OrderCommentApi.OrderCommentParams(response.getValue("ORDER_ID")),
                respGetOrderCommentListener, errorListener));
    }

    @Override
    public void initView() {
        titleBar.setTitle("查看评论");
        ninePhotoLayout = (BGASortableNinePhotoLayoutView) findViewById(R.id.activity_discover_invest_publish_nine_photo);
        ninePhotoLayout.init(CommentShowActivity.this);
        ninePhotoLayout.setDelegate(CommentShowActivity.this);

    }

    Response.Listener<OrderCommentResult> respGetOrderCommentListener = new Response.Listener<OrderCommentResult>() {

        @Override
        public void onResponse(OrderCommentResult response) {

            if (HandleCode.requestSuccess()) {
                mRbskill.setRating(StringUtil.parseFloat(response.getTechCAP()));
                mRbservice.setRating(StringUtil.parseFloat(response.getServiceCAP()));
                mRbspeed.setRating(StringUtil.parseFloat(response.getSpeedCAP()));

                etRemark.setText(response.getContent());

                String path = response.getPic();
                selectedPhotos = StringUtil.getListWithPath(path,",");
                ninePhotoLayout.setData(selectedPhotos);
                Log.i("juner", "juner response OrderCommentResult: " + GsonHelper.writeValue(response));
            } else {

            }
        }
    };


    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());

        }
    };


    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_comment_show;
    }


    @Override
    public void onClickNinePhotoItem(BGASortableNinePhotoLayoutView ninePhotoLayout, View view, int position, String model, List<String> models) {
        startActivity(BGAPhotoPreviewActivity.newIntent(this, null, (ArrayList<String>) models, position));
    }

    @Override
    public boolean onLongClickNinePhotoItem(BGASortableNinePhotoLayoutView ninePhotoLayout, View view, int position, String model, List<String> models) {
        return false;
    }
}
